package com.ws.test09.util;

import com.ws.test09.entity.Student;

/**
 * @author 王硕
 * @version jdk21
 * @className StudentComparable
 * @description
 * @date 2024/11/22 8:56
 */
public class StudentComparable extends Student implements Comparable<StudentComparable>{

    public StudentComparable(int id, String name, int age, double score) {
        super(id, name, age, score);
    }

    @Override
    public int compareTo(StudentComparable other) {
        // 先按成绩降序排序
        if (this.score != other.score) {
            return Double.compare(other.score, this.score);
        }
        // 成绩相同，按年龄升序排序
        return Integer.compare(this.age, other.age);
    }
}
